#ifndef __CHANNEL_HPP__
#define __CHANNEL_HPP__
#endif 

#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <functional>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>

// 先描述，管道通信通道
class Channel
{
public:
    Channel(int wfd, pid_t id)
        : _wfd(wfd), _who(id)
    {
        _name = "Channel-" + std::to_string(_wfd) + '-' + std::to_string(_who);
    }
    std::string Name() const
    {
        return _name;
    }

    int Send(int cmd)
    {
        return ::write(_wfd, &cmd, sizeof cmd);
    }
    int wFd()
    {
        return _wfd;
    }
    void Close()
    {
        ::close(_wfd);
    }
    pid_t Id()
    {
        return _who;
    }
    ~Channel()
    {
    }

private:
    int _wfd;   // 写入管道
    pid_t _who; // 子进程pid
    std::string _name;
};

